import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.sansui.FilterChiam.FilterContent;
import com.sansui.FilterChiam.FilterModel;
import com.sansui.FilterChiam.FilterRegular;
import com.sansui.FilterChiam.FilterSpilth;
import com.sansui.Untls.Untls;


public class Catcher {

	static FilterRegular filters[] = {new FilterContent() , new FilterModel(),new FilterSpilth()};
	
	/**
	 * @param 40690-40809;
	 */
	public static void main(String[] args) {
		CatchHelper ch = new CatchHelper();
		List<String> list = new ArrayList<String>(); 
		
		/* 
		 * for(int i = 40690 ; i <= 40809 ; i++ ){
			String url = "http://www.educity.cn/ite/" + i + ".html";
			String urlRst = ch.dowmSites(url);
			list.add(urlRst);
		}*/
		
		//40691,40692,40803,40804,40807,40808,40809,40798,40791,40786,
		//40784,40758,40754,40751,40749,40748,40747,40746,40742,40740,40739,40738,40737,40736
		//40735,40734,40732,40730,40727,40726,40725,40721,40719
		
		int arraySite[] = {40691,40692,40803,40804,40807,40808,40809,40798,40791,40786,
				40784,40758,40754,40751,40749,40748,40747,40746,40742,40740,40739,40738,40737,40736,
				40735,40734,40732,40730,40727,40726,40725,40721,40719};
		
		
		for(int i = 0 ;i < arraySite.length ;i++ ){
			String urlRst = ch.dowmSites("http://www.educity.cn/ite/"+arraySite[i]+".html");
			list.add(urlRst);
		}
		
		
		List<String> listRes = new ArrayList<String>();
		for(int i = 0 ; i < list.size() ; i++){
			String content = list.get(i);
			for(FilterRegular f : filters){
				content = f.filterRegular(content);
			}
			listRes.add(content);
		}
		
		for(int i = 0 ; i < listRes.size() ; i++){
			String content = listRes.get(i);
			File file = new File("C:\\Users\\user\\Desktop\\Content.txt");
			try {
				FileOutputStream fos =new FileOutputStream(file);
				InputStream in = Untls.getStringInputStream(content);
				int line = 0;
				byte[] array = new byte[1024];
				while((line = in.read(array)) != -1){
					fos.write(array, 0, array.length);
				}
			} catch (IOException e) {
				e.printStackTrace();
			} 
		}
	}
}
